package cn.iocoder.yudao.module.infra.controller.admin.weather;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.infra.controller.admin.weather.vo.WeatherRespVO;
import cn.iocoder.yudao.module.infra.filter.IpAddressFilter;
import cn.iocoder.yudao.module.infra.service.weather.WeatherService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

/**
 * 管理后台 - 天气信息
 */
@Tag(name = "管理后台 - 天气信息")
@RestController
@RequestMapping("/infra/weather")
@Validated
public class WeatherController {

    @Resource
    private WeatherService weatherService;

    @GetMapping("/get-15-days")
    @Operation(summary = "获取最近15天的天气信息")
    public CommonResult<WeatherRespVO> get15DaysWeather(HttpServletRequest request) {
        // 从请求属性中获取IP地址
        String ip = (String) request.getAttribute(IpAddressFilter.REQUEST_ATTRIBUTE_IP);
        // 调用服务获取天气信息
        WeatherRespVO weatherInfo = weatherService.get15DaysWeather(ip);
        return success(weatherInfo);
    }
}

